package com.example.yls.demoa;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class AddActivity extends AppCompatActivity {
    private EditText edt_Name;
    private EditText edt_Age;
    private RadioButton radio_Button1;
    private RadioButton radio_Button2;
    private RadioButton radio_Button3;
    private RadioButton radio_Button4;
    private RadioButton radio_Button5;
    private Button btn_Add;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);

        setTitle("添加学生窗口");

        edt_Name=findViewById(R.id.edtName);
        edt_Age=findViewById(R.id.edtAge);

        radio_Button1=findViewById(R.id.radioButton1);
        radio_Button2=findViewById(R.id.radioButton2);
        radio_Button3=findViewById(R.id.radioButton3);
        radio_Button4=findViewById(R.id.radioButton4);
        radio_Button5=findViewById(R.id.radioButton5);

        btn_Add=findViewById(R.id.btnAdd);

        btn_Add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name=edt_Name.getText().toString();

                int age=Integer.parseInt(edt_Age.getText().toString());

                int imgId=R.drawable.dog1;

                if(radio_Button1.isChecked()){
                    imgId=R.drawable.dog1;
                }else if(radio_Button2.isChecked()){
                    imgId=R.drawable.dog2;
                }else if(radio_Button3.isChecked()){
                    imgId=R.drawable.dog3;
                }else if(radio_Button4.isChecked()){
                    imgId=R.drawable.dog4;
                }else if(radio_Button5.isChecked()){
                    imgId=R.drawable.dog5;
                }

                Intent intent=new Intent();

                intent.putExtra("Name",name);
                intent.putExtra("Age",age);
                intent.putExtra("ImgId",imgId);
                setResult(2001,intent);

                finish();
            }
        });

    }
}
